//====================================================================
// File Name : mgdrv-ucosii.c
//====================================================================
#include "common.h"
#include "minigui.h"
#include "gdi.h"
#include "window.h"
#include "ucos_ii.h"

/* --------------------- I/O functions -------------------------- */
// for debug purpose

/* Gets a char from uart */
BYTE drv_uart_get_byte (void)
{
    //...
    return(0);
}

/* Sends a char to uart */
void drv_uart_send_byte (BYTE ch)
{
    //...
}


/* ------------------- Application entry for uC/OS-II -------------- */
/* for reference only */

/*
 * main task of MiniGUI
 */
static void* mg_main_task (void* args)
{
    /*
     * Enter entry in MiniGUI library
     */
    minigui_entry (0, NULL);
    
    while(1)
    {   
        OSTimeDly (100);
    }

    return NULL;
}

/*
 * MiniGUI entry for uC/OS-II
 * You can call this function before you call OSStart.
 */
void minigui_app_entry (void)
{
    pthread_t main_thread;

    /*
     * Should initialize heap memory management module first
     * before using MiniGUI.
     */
    if (ucos2_malloc_init ()) {
        fprintf (stderr, "Can not init our own malloc implementation for uC/OS-II.\n");
        return;
    }
    /*
     * Should initialize POSIX thread module first
     * before using MiniGUI.
     */
    if (ucos2_posix_pthread_init ()) {
        fprintf (stderr, "Can not init our own pthread implementation for uC/OS-II.\n");
        return;
    }

    /*
     * Creating a independent thread for MiniGUI main task is a good idea.
     */
	pthread_create (&main_thread, NULL, mg_main_task, NULL);
}

